package com.aaa.service.Impl;

import com.aaa.common.domain.*;
import com.aaa.common.result.RentQuery;
import com.aaa.common.result.Result;
import com.aaa.mapper.*;
import com.aaa.service.RentService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;


/**
 * @className RentServiceImpl
 * @Description TODO
 * @Author wyy
 * @Data 2021/1/23 20:47
 * @Version 1.0
 */
@Service
public class RentServiceImpl implements RentService {

    //租入
    @Autowired
    private RentInAssetInfoMapper rentInAssetInfoMapper;
    //资产公司分类
    @Autowired
    private AssetCompanyMapper assetCompanyMapper;
    @Autowired
    private EcoHourseTypeMapper ecoHourseTypeMapper;
    @Autowired
    private RentAllInfoMapper rentAllInfoMapper;
    @Autowired
    private EcoHourseType hourseType;
    @Autowired
    //公司实体类
    private AssetCompany company;
    @Autowired
    //租入实体类
    private RentInAssetInfo rentInAssetInfo;
    @Autowired
    private RentAllInfo rentAllInfo;

    //房产证屋类型
    /**
     *@ 描述 租入信息查询
     *@ 创建人 王阳
     *@ 创建时间 2021/1/28 10:30
     *@ 修改人和其它信息  暂无
     */


    /**
     *@ 描述 :租入查询+分页+模糊查询
     */
   @Override
    public Result rentList(RentQuery rentQuery) {
       Page<RentAllInfo> objectPage = new Page<>(rentQuery.getPage(),rentQuery.getCount());
        Page<RentAllInfo> rentInfo = rentAllInfoMapper.rentInfo(objectPage,rentQuery.getAssetId(),rentQuery.getGroupName());
        if (rentInfo!=null) return Result.success(rentInfo);
        else return Result.error("返回的数据为null");
    }
    /**
     *@ 描述 :资产公司分类
     */
    @Override
    public Result companyList() {
        QueryWrapper<AssetCompany> objectQueryWrapper = new QueryWrapper<>();
        List<AssetCompany> assetCompanies = assetCompanyMapper.selectList(objectQueryWrapper);
        System.out.println(assetCompanies);
        return Result.success(assetCompanies);
    }
    /**
     *@ 描述 :房产证屋类型的查询
     */
    @Override
    public Result typeList() {
        QueryWrapper<EcoHourseType> objectQueryWrapper = new QueryWrapper<>();
        List<EcoHourseType> ecoHourseTypes = ecoHourseTypeMapper.selectList(objectQueryWrapper);
        if (ecoHourseTypes!=null) return Result.success(ecoHourseTypes);
        else return Result.error("查询有误");
    }



    /**
     *@ 描述 :公司的添加
     */
    @Override
    public Result companyAdd(AssetCompany assetCompany) {
        int insert = assetCompanyMapper.insert(assetCompany);
        if (insert>0) return Result.success("添加成功");
        else return Result.error("添加失败");
    }
    /**
     *@ 描述 :房产类型的添加
     */
    @Override
    public Result typeAdd(EcoHourseType ecoHourseType) {
        int insert = ecoHourseTypeMapper.insert(ecoHourseType);
        if (insert>0) return Result.success("添加成功");
        else return Result.error("添加失败");
    }
    /**
     *@ 描述 :根据ID查询一条数据
     */
    @Override
    public Result rentUpdateById(int id) {
        RentInAssetInfo rentInAssetInfo = rentInAssetInfoMapper.selectById(id);
        if(rentAllInfo!=null) return Result.success(rentInAssetInfo);
        else return Result.error("查询失败");
    }




    /**
     *@ 描述 :租入信息的修改
     */
    @Override
    public Result rentUpdates(RentInAssetInfo rentInAssetInfo) {
        int i = rentInAssetInfoMapper.updateById(rentInAssetInfo);
        if (i>0) return Result.success("修改成功");
        else return Result.error("修改失败");
    }
    /**
     *@ 描述 :租入信息的添加
     */
    @Override
    public Result rentAdd(RentInAssetInfo rentInAssetInfo) {
        int i = rentInAssetInfoMapper.insert(rentInAssetInfo);
        if (i>0) return Result.success("添加成功");
        else return Result.error("添加失败");
    }
    /**
     *@ 描述 :租入信息的删除
     */
    @Override
    public Result rentDelete(String ids) {
        String[] split = ids.split(",");   //分割数组
        List<String> strings = Arrays.asList(split);  //转化为list数组  ？？？？？？？？
        int i = rentInAssetInfoMapper.deleteBatchIds(strings);
        if (i>0) return Result.success("删除成功");
        else return Result.error("删除失败");
    }
}
